/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.Business.GuildEntry
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-07-29 -- Cliff Simpkins: Initial Version
 * 2007-08-02 -- Cliff Simpkins: Added properties and constructors
 * 2007-09-02 -- Cliff Simpkins: Added guild roster values and
 *                 speclialization summary information
 * 2007-12-15 -- Cliff Simpkins: Added HTML for AJAX behavior
 * 2007-12-27 -- Cliff Simpkins: Logic for graphic generation
 * 2007-03-16 -- Cliff Simpkins: Trimmed to use c# v3 and added LoadStatus
 **********************************************************************
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;

using DotNetWarcraft.Common;

namespace DotNetWarcraft.WoWGuildRoster.Business {
  /// <summary>
  /// Character entry that represents one game character, and should be attached to a Guild Roster.
  /// </summary>
  public class GuildEntry {
    #region Protected Members

    //Guild accounting and tracking information
    protected int _game_guild_rank;
    protected String _game_guild_notes;
    protected String _game_officer_notes;

    //Main and alt tracking information
    protected int _primary_char_flag;
    protected int _alt_to_main_id;

    //Audit information
    protected DateTime _last_load_date;
    protected int _last_load_id;
    protected DateTime _last_update_date;
    protected int _last_update_by;
    #endregion
    #region Public Properties
    public int Char_ID {
      get;
      set;
      }
    public int Roster_ID {
      get;
      set;
      }
    public int Current_Flag {
      get;
      set;
      }
    public int LoadStatus {
      get;
      set;
      }
    public WGR_LoadStatus LoadStatus_Enum {
      get {
        return WGRConstants.LoadStatus_Enum(this.LoadStatus);
        }
      set {
        this.LoadStatus = WGRConstants.LoadStatus_Int(value);
        }
      }

    //Although this information is stored in the roster, we also track this in the guild entry
    //  because characters can change servers and guilds. And we would like to be able know why
    //  entries disappear beyond simply having the 'current flag' toggle.
    public String Char_Server {
      get;
      set;
      }
    public String Char_Guild {
      get;
      set;
      }
    public int Char_Region {
      get;
      set;
      }
    public WarcraftRegions Char_Region_Enum {
      get {
        return WGRConstants.WowRegion_Enum(this.Char_Region);
        }
      set {
        this.Char_Region = WGRConstants.WowRegion_Int(value);
        }
      }

    //Basic character information
    public String Char_Name {
      get;
      set;
      }
    public String Char_Race {
      get;
      set;
      }
    public String Char_Gender {
      get;
      set;
      }
    public String Char_Class {
      get;
      set;
      }
    public int Char_Level {
      get;
      set;
      }
    public DateTime Game_Last_Login {
      get;
      set;
      }

    //Specialization Information
    public int Char_Spec_Num {
      get;
      set;
      }
    public String Char_Spec {
      get;
      set;
      }
    public String Char_Spec1 {
      get;
      set;
      }
    public int Char_Spec1_Level {
      get;
      set;
      }
    public String Char_Spec2 {
      get;
      set;
      }
    public int Char_Spec2_Level {
      get;
      set;
      }
    public String Char_Spec3 {
      get;
      set;
      }
    public int Char_Spec3_Level {
      get;
      set;
      }

    //Profession Information
    public String Char_Prof1 {
      get;
      set;
      }
    public int Char_Prof1_Level {
      get;
      set;
      }
    public String Char_Prof2 {
      get;
      set;
      }
    public int Char_Prof2_Level {
      get;
      set;
      }

    public int Game_Guild_Rank {
      get { return _game_guild_rank; }
      set { _game_guild_rank = value; }
      }
    public String Game_Guild_Notes {
      get { return _game_guild_notes; }
      set { _game_guild_notes = value; }
      }
    public String Game_Officer_Notes {
      get { return _game_officer_notes; }
      set { _game_officer_notes = value; }
      }

    public int Primary_Char_Flag {
      get { return _primary_char_flag; }
      set { _primary_char_flag = value; }
      }
    public int Alt_to_Main_ID {
      get { return _alt_to_main_id; }
      set { _alt_to_main_id = value; }
      }

    public DateTime Last_Load_Date {
      get { return _last_load_date; }
      set { _last_load_date = value; }
      }
    public int Last_Load_ID {
      get { return _last_load_id; }
      set { _last_load_id = value; }
      }
    public DateTime Last_Update_Date {
      get { return _last_update_date; }
      set { _last_update_date = value; }
      }
    public int Last_Update_By {
      get { return _last_update_by; }
      set { _last_update_by = value; }
      }
    #endregion
    #region Interpreted Properties
    public bool NeedsToBeUpdated {
      get {
        if (this.Char_ID < 0 || this.Char_Name == "") {
          return true;
          } else if (this.LoadStatus_Enum == WGR_LoadStatus.NewOrEmpty) {
          return true;
          } else if (this.LoadStatus_Enum == WGR_LoadStatus.ReloadRequired) {
          return true;
          } else if (this.LoadStatus_Enum == WGR_LoadStatus.Uninitialized) {
          return true;
          } else if ((this.Char_Spec1_Level + this.Char_Prof2_Level + this.Char_Spec3_Level) < this.Char_Level - 9) {
          return true;
          } else {
          return false;
          }
        }
      }
    public String CharInfo_Spec1 {
      get {
        if (this.Char_Spec1_Level == 0) {
          //TO DO: Add Localization
          return "";
          } else {
          return this.Char_Spec1_Level + " " + this.Char_Spec1;
          }
        }
      }
    public String CharInfo_Spec2 {
      get {
        if (this.Char_Spec2_Level == 0) {
          return "";
          } else {
          return this.Char_Spec2_Level + " " + this.Char_Spec2;
          }
        }
      }
    public String CharInfo_Spec3 {
      get {
        if (this.Char_Spec3_Level == 0) {
          return "";
          } else {
          return this.Char_Spec3_Level + " " + this.Char_Spec3;
          }
        }
      }
    public String CharInfo_SpecOverview {
      get {
        if (this.Char_Spec1_Level == 0 && this.Char_Spec2_Level == 0 && this.Char_Spec3_Level == 0) {
          //TO DO: Add Localization
          return "No Specializations Yet";
          } else {
          bool _addSep = false;
          String _spec = "";

          _spec += this.Char_Spec;
          _spec += " (";
          if (this.Char_Spec1_Level > 0) {
            _spec += this.CharInfo_Spec1;
            _addSep = true;
            }
          if (this.Char_Spec2_Level > 0) {
            if (_addSep) {
              _spec += " / ";
              }
            _spec += this.CharInfo_Spec2;
            _addSep = true;
            }
          if (this.Char_Spec3_Level > 0) {
            if (_addSep) {
              _spec += " / ";
              }
            _spec += this.CharInfo_Spec3;
            }
          _spec += ")";
          return _spec;
          }
        }
      }
    public String CharInfo_SpecNumbers {
      get {
        return this.Char_Spec1_Level.ToString() + "/" +
          this.Char_Spec2_Level.ToString() + "/" +
          this.Char_Spec3_Level.ToString();
        }
      }
    public String Game_Last_Login_Day {
      get { return this.Game_Last_Login.ToShortDateString(); }
      }

    public String Game_Activity {
      get {
        TimeSpan _ts = DateTime.Today - this.Game_Last_Login;

        if (_ts.Days < 1) { return "Played Today"; } else if (_ts.Days <= 7) { return "Played this week"; } else if (_ts.Days <= 14) { return "Played in last couple weeks"; } else if (_ts.Days <= 31) { return "Played this month"; } else if (_ts.Days <= 60) { return "Not seen in a month"; } else if (_ts.Days <= 90) { return "Not seen in a couple months"; } else if (_ts.Days <= 180) { return "Not seen in a few months"; } else if (_ts.Days <= 360) { return "Not in at least 6 months"; } else { return "Inactive; Not seen in the last year!"; }
        }
      }
    /*
    public GuildEntry MainCharacter {
      get {
        if (this.Alt_to_Main_ID < 0) {
          return new GuildEntry();
          }

        try {
          return GuildRosterController.GetCharEntry(this.Alt_to_Main_ID);
          } catch {
          return new GuildEntry();
          }
        }
      set {
        if (value.Char_ID > 0) {
          this.Alt_to_Main_ID = value.Char_ID;
          }
        }
      }
    public List<GuildEntry> AltCharacters {
      get {
        if (this.Char_ID < 0) { return null; }

        try {
          return GuildRosterController.GetCharEntries_Alts(this.Char_ID);
          } catch {
          return null;
          }
        }
      }
    public List<GuildEntryStat> Stats_All {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharEntry(this.Char_ID);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }

    public List<GuildEntryStat> BaseStats {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.BaseCharStats);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> Reputations {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.Reputation);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> Abilities {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.Ability);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> ArmorSkills {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.ArmorSkill);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> DefenseSkills {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.DefenseSkill);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> MeleeSkills {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.MeleeSkill);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> RangedSkills {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.RangedSkill);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> Resistances {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.Resistances);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> SecondarySkills {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.SecondarySkill);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> SpellSkills {
      get {
        List<GuildEntryStat> _charStats;

        if (this.Char_ID >= 0) {
          _charStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.SpellSkill);
          } else {
          _charStats = new List<GuildEntryStat>();
          }
        return _charStats;
        }
      }
    public List<GuildEntryStat> ArenaTeamInfo {
      get {
        List<GuildEntryStat> _arenaStats;

        if (this.Char_ID >= 0) {
          _arenaStats = GuildRosterController.GetCharEntryStats_ByCharAndType(this.Char_ID, WarcraftStatTypes.ArenaTeamInfo);
          } else {
          _arenaStats = new List<GuildEntryStat>();
          }
        return _arenaStats;
        }
      }

    public GuildRoster Guild {
      get {
        if (this.Roster_ID < 0) {
          return new GuildRoster();
          }

        try {
          return GuildRosterController.GetRoster(this.Roster_ID);
          } catch {
          return new GuildRoster();
          }
        }
      set {
        if (value.Roster_ID > 0) {
          this.Roster_ID = value.Roster_ID;
          }
        }
      }
    public String Game_Guild_RankName {
      get {
        if (this.Roster_ID >= 0 && this.Guild.Roster_ID >= 0) {
          return this.Guild.GetGuildRank(this.Game_Guild_Rank);
          } else
          return "N/A";
        }
      }
    */

    public String ArmoryLink_CharInfo {
      get {
        return WGRConstants.ArmoryURL_CharInfo(this.Char_Region_Enum, this.Char_Name, this.Char_Server);
        }
      }
    public String ArmoryLink_RepInfo {
      get {
        return WGRConstants.ArmoryURL_RepInfo(this.Char_Region_Enum, this.Char_Name, this.Char_Server);
        }
      }
    public String ArmoryLink_SkillsInfo {
      get {
        return WGRConstants.ArmoryURL_SkillsInfo(this.Char_Region_Enum, this.Char_Name, this.Char_Server);
        }
      }
    public String ArmoryLink_Talents {
      get {
        return WGRConstants.ArmoryURL_TalentsInfo(this.Char_Region_Enum, this.Char_Name, this.Char_Server);
        }
      }

    public String CharIcon {
      get {
        String _imgUrl = "http://" + WGRConstants.ArmoryServer(WarcraftRegions.RegionUS) + "/images/portraits/";
        if (this.Char_Level >= 70) {
          _imgUrl += "wow-70/";
          } else if (this.Char_Level >= 60) {
          _imgUrl += "wow/";
          } else {
          _imgUrl += "wow-default/";
          }

        switch (this.Char_Gender.ToLower()) {
          case "female":
            _imgUrl += "1-"; break;
          case "male":
          default:
            _imgUrl += "0-"; break;
          }

        switch (this.Char_Race.ToLower()) {
          case "bloodelf":
            _imgUrl += "10-"; break;
          case "draenei":
            _imgUrl += "11-"; break;
          case "dwarf":
            _imgUrl += "3-"; break;
          case "gnome":
            _imgUrl += "7-"; break;
          case "nightelf":
            _imgUrl += "4-"; break;
          case "orc":
            _imgUrl += "2-"; break;
          case "tauren":
            _imgUrl += "6-"; break;
          case "troll":
            _imgUrl += "8-"; break;
          case "undead":
            _imgUrl += "5-"; break;
          case "human":
          default:
            _imgUrl += "1-"; break;
          }

        switch (this.Char_Class.ToLower()) {
          case "deathknight":
            _imgUrl += "6"; break;
          case "druid":
            _imgUrl += "11"; break;
          case "hunter":
            _imgUrl += "3"; break;
          case "mage":
            _imgUrl += "8"; break;
          case "paladin":
            _imgUrl += "2"; break;
          case "priest":
            _imgUrl += "5"; break;
          case "rogue":
            _imgUrl += "4"; break;
          case "shaman":
            _imgUrl += "7"; break;
          case "warlock":
            _imgUrl += "9"; break;
          case "warrior":
          default:
            _imgUrl += "1"; break;
          }
        return _imgUrl += ".gif";

        }
      }
    /*
    public String PopupHtml {
      get {
        String _output = "";
        _output += "<span class=\\'" + this.Char_Class.ToLower() + "Ch\\'>" + this.Char_Name + "</span><br>";
        if (this.Game_Guild_RankName.Trim() != "" && this.Char_Guild.Trim() != "") {
          _output += this.Game_Guild_RankName + " of " + this.Char_Guild + "<br>";
          } else if (this.Char_Guild.Trim() != "") {
          _output += "Of " + this.Char_Guild + "<br>";
          }
        _output += "Level " + this.Char_Level + " " + this.Char_Class + "<br>";
        if (this.Char_Level > 20) {
          if ((this.Char_Spec1_Level + this.Char_Spec2_Level + this.Char_Spec3_Level > 0) && this.Char_Spec1_Level >= 0 && this.Char_Spec2_Level >= 0 && this.Char_Spec3_Level >= 0) {
            if (this.Char_Spec_Num > 0) {
              _output += "<img src=\\'{imgDir}/IconSmall_" + this.Char_Class.ToLower() + "-" + this.Char_Spec_Num.ToString() + ".png\\' align=left>";
              }
            _output += " (";
            if (this.Char_Spec != "") {
              _output += this.Char_Spec + " - ";
              }
            _output += this.Char_Spec1_Level.ToString() + "/" + this.Char_Spec2_Level.ToString() + "/" + this.Char_Spec3_Level.ToString() + ")<br>";
            } else {
            _output += "(Spec Info Unavailable)<br>";
            }
          }
        if (this.Primary_Char_Flag > 0) {
          List<GuildEntry> _alts = this.AltCharacters;
          if (_alts.Count > 0) {
            _output += "[" + _alts.Count.ToString() + " registered alts]";
            } else {
            _output += "[Main character]";
            }
          _output += "<br>";
          } else if (this.Alt_to_Main_ID > 0) {
          _output += "[Alt to " + this.MainCharacter.Char_Name + "]";
          _output += "<br>";
          }

        if (this.Char_Prof1.Trim() != "" || this.Char_Prof2.Trim() != "") {
          _output += "<br>";
          if (this.Char_Prof1.Trim() != "") {
            if (this.Char_Prof1_Level > 350) {
              _output += "<span class=\\'purplename\\'>";
              } else if (this.Char_Prof1_Level > 300) {
              _output += "<span class=\\'bluename\\'>";
              } else if (this.Char_Prof1_Level > 225) {
              _output += "<span class=\\'greenname\\'>";
              } else if (this.Char_Prof1_Level > 150) {
              _output += "<span class=\\'whitename\\'>";
              } else {
              _output += "<span class=\\'greyname\\'>";
              }
            _output += this.Char_Prof1_Level.ToString() + " " + this.Char_Prof1 + "</span><br>";
            }
          if (this.Char_Prof2.Trim() != "") {
            if (this.Char_Prof2_Level > 350) {
              _output += "<span class=\\'purplename\\'>";
              } else if (this.Char_Prof2_Level > 300) {
              _output += "<span class=\\'bluename\\'>";
              } else if (this.Char_Prof2_Level > 225) {
              _output += "<span class=\\'greenname\\'>";
              } else if (this.Char_Prof2_Level > 150) {
              _output += "<span class=\\'whitename\\'>";
              } else {
              _output += "<span class=\\'greyname\\'>";
              }
            _output += this.Char_Prof2_Level.ToString() + " " + this.Char_Prof2 + "</span><br>";
            }
          }
        return _output;
        }
      }
    public String WowHeadHoverHtml {
      get {
        return "<table class='wh_outer'>" +
                 "<tr><td width='300px'>" +
                   "<table class='wowhead_tooltip'>" +
                     "<tr>" +
                       "<td class='top-left'></td>" +
                       "<td class='top-right'></td>" +
                     "</tr>" +
                     "<tr>" +
                       "<td colspan='2' class='wh_left'>" +
                         "<div class='wh_right'>" + this.PopupHtml + "</div>" +
                       "</td>" +
                     "</tr>" +
                     "<tr>" +
                       "<td class='bottom-left'></td>" +
                       "<td class='bottom-right'></td>" +
                     "</tr>" +
                   "</table>" +
                 "</td></tr>" +
               "</table>";
        }
      }

    public System.Drawing.Bitmap SigGraphic {
      get {
        System.Drawing.Bitmap _bmp = new Bitmap(500, 150, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
        System.Drawing.Graphics _sig = Graphics.FromImage(_bmp);

        System.Drawing.Color _colorHolder = Color.WhiteSmoke;
        System.Drawing.Color _colorBg = Color.Blue;
        System.Drawing.Color _colorText = Color.Gold;
        System.Drawing.Font _fCharName = new Font("Arial", 20, FontStyle.Bold);
        System.Drawing.Font _fGuildTag = new Font("Arial", 14, FontStyle.Bold);
        System.Drawing.Font _fSpecTag = new Font("Arial", 12, FontStyle.Bold);
        System.Drawing.Font _fAlts = new Font("Arial", 10, FontStyle.Bold);

        System.Drawing.SolidBrush _brushBg = new SolidBrush(_colorBg);
        System.Drawing.SolidBrush _brushText = new SolidBrush(_colorText);
        System.Drawing.SolidBrush _brushHolder = new SolidBrush(_colorHolder);

        _sig.Clear(_colorBg);
        //_sig.FillRectangle(_brushBg, 0, 0, 300, 100);

        //System.Drawing.Image _charImg;
        //_charImg = System.Drawing.Image.FromFile(this.CharIcon);
        //_sig.DrawImage(_charImg, 10, 10, 64, 64);
        _sig.FillRectangle(_brushHolder, 10, 10, 64, 64);

        StringFormat _format = new StringFormat();

        _sig.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        _sig.DrawString(this.Char_Name, _fCharName, _brushText, 74, 10);
        _sig.DrawString(this.Game_Guild_RankName + " of <" + this.Char_Guild + ">", _fGuildTag, _brushText, 94, 35);
        _sig.DrawString(this.Char_Level + " " + this.Char_Spec + " " + this.Char_Class + " (" + this.CharInfo_SpecNumbers + ")", _fSpecTag, _brushText, 94, 55);

        List<GuildEntry> _alts = this.AltCharacters;

        for (int _i = 0; _i < _alts.Count && _i < 4; _i++) {
          int _altX = 0, _altY = 0;
          switch (_i) {
            case 0:
              _altX = 0; _altY = 0; break;
            case 1:
              _altX = 0; _altY = 30; break;
            case 2:
              _altX = 230; _altY = 0; break;
            case 3:
              _altX = 230; _altY = 30; break;
            }

          _sig.DrawString(_alts[_i].Char_Name + ": " + _alts[_i].Char_Level.ToString() + " " + _alts[_i].Char_Class,
                          _fAlts, _brushText, 50 + _altX, 85 + _altY);

          }
        return _bmp;
        }
      }
    */
    #endregion
    #region Constructors
    public GuildEntry()
      : base() {
      this.Char_ID = -1;
      this.Roster_ID = -1;
      this.Current_Flag = 0;
      this.LoadStatus_Enum = WGR_LoadStatus.Uninitialized;

      this.Char_Server = "";
      this.Char_Guild = "";
      this.Char_Region_Enum = WarcraftRegions.RegionUnknown;

      this.Char_Name = "";
      this.Char_Race = "";
      this.Char_Gender = "";
      this.Char_Class = "";
      this.Char_Level = -1;
      this.Game_Last_Login = DateTime.MinValue;

      this.Char_Spec_Num = -1;
      this.Char_Spec = "";
      this.Char_Spec1 = "";
      this.Char_Spec1_Level = -1;
      this.Char_Spec2 = "";
      this.Char_Spec2_Level = -1;
      this.Char_Spec3 = "";
      this.Char_Spec3_Level = -1;

      this.Char_Prof1 = "";
      this.Char_Prof1_Level = -1;
      this.Char_Prof2 = "";
      this.Char_Prof2_Level = -1;

      this.Game_Guild_Rank = -1;
      this.Game_Guild_Notes = "";
      this.Game_Officer_Notes = "";

      this.Primary_Char_Flag = 0;
      this.Alt_to_Main_ID = -1;

      this.Last_Load_Date = DateTime.MinValue;
      this.Last_Load_ID = -1;
      this.Last_Update_By = -1;
      this.Last_Update_Date = DateTime.MinValue;

      }

    public GuildEntry(int charID)
      : base() {
      this.Char_ID = charID;
      }

    public GuildEntry(DataRow rosterSrc)
      : base() {
      this.Char_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["char_id"]);
      this.Roster_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["roster_id"]);
      this.Char_Server = SqlDataUtils.RetrieveDbString(rosterSrc["char_server"]);
      this.Char_Guild = SqlDataUtils.RetrieveDbString(rosterSrc["char_guild"]);
      this.Char_Region = SqlDataUtils.RetrieveDbInt(rosterSrc["char_region"]);

      this.LoadStatus = SqlDataUtils.RetrieveDbInt(rosterSrc["char_status"]);
      this.Current_Flag = SqlDataUtils.RetrieveDbInt(rosterSrc["current_flag"]);

      this.Char_Name = SqlDataUtils.RetrieveDbString(rosterSrc["char_name"]);
      this.Char_Race = SqlDataUtils.RetrieveDbString(rosterSrc["char_race"]);
      this.Char_Gender = SqlDataUtils.RetrieveDbString(rosterSrc["char_gender"]);
      this.Char_Class = SqlDataUtils.RetrieveDbString(rosterSrc["char_class"]);
      this.Char_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_level"]);
      this.Game_Last_Login = SqlDataUtils.RetrieveDbDate(rosterSrc["game_last_login"]);

      this.Char_Spec_Num = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec_num"]);
      this.Char_Spec = SqlDataUtils.RetrieveDbString(rosterSrc["char_spec"]);
      this.Char_Spec1 = SqlDataUtils.RetrieveDbString(rosterSrc["char_spec1"]);
      this.Char_Spec1_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec1_level"]);
      this.Char_Spec2 = SqlDataUtils.RetrieveDbString(rosterSrc["char_spec2"]);
      this.Char_Spec2_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec2_level"]);
      this.Char_Spec3 = SqlDataUtils.RetrieveDbString(rosterSrc["char_spec3"]);
      this.Char_Spec3_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec3_level"]);
      this.Char_Prof1 = SqlDataUtils.RetrieveDbString(rosterSrc["char_prof1"]);
      this.Char_Prof1_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_prof1_level"]);
      this.Char_Prof2 = SqlDataUtils.RetrieveDbString(rosterSrc["char_prof2"]);
      this.Char_Prof2_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_prof2_level"]);

      this.Game_Guild_Rank = SqlDataUtils.RetrieveDbInt(rosterSrc["game_guild_rank"]);
      this.Game_Guild_Notes = SqlDataUtils.RetrieveDbString(rosterSrc["game_guild_notes"]);
      this.Game_Officer_Notes = SqlDataUtils.RetrieveDbString(rosterSrc["game_officer_notes"]);

      this.Primary_Char_Flag = SqlDataUtils.RetrieveDbInt(rosterSrc["primary_char"]);
      this.Alt_to_Main_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["alt_to_main"]);

      this.Last_Load_Date = SqlDataUtils.RetrieveDbDate(rosterSrc["last_load_date"]);
      this.Last_Load_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["last_load_id"]);

      this.Last_Update_Date = SqlDataUtils.RetrieveDbDate(rosterSrc["last_update_date"]);
      this.Last_Update_By = SqlDataUtils.RetrieveDbInt(rosterSrc["last_update_by"]);
      }

    #endregion

    #region "Public Methods"
    /*
    public void MakePrimaryCharacter() {

      if (this.Alt_to_Main_ID > 0) {
        GuildEntry _main = GuildRosterController.GetCharEntry(this.Alt_to_Main_ID);

        if (_main.Char_ID > 0) {
          foreach (GuildEntry _alt in _main.AltCharacters) {

            if (_alt.Char_ID != this.Char_ID) {
              _alt.Primary_Char_Flag = 0;
              _alt.Alt_to_Main_ID = this.Char_ID;
              GuildRosterController.UpdateCharEntry(_alt);
              }
            }

          _main.Primary_Char_Flag = 0;
          _main.Alt_to_Main_ID = this.Char_ID;

          }
        }

      this.Primary_Char_Flag = 1;
      this.Alt_to_Main_ID = -1;
      //throw new Exception("Method Not Implemented - GuildEntry.MakePrimaryCharacter");

      }
    public void LinkToPrimaryCharacter(int mainCharID) {

      throw new Exception("Method Not Implemented - GuildEntry.LinkToPrimaryCharacter");

      }

    public List<GuildEntryStat> Reputations_ByGroup(String repGroup) {
      List<GuildEntryStat> _charStats;

      if (this.Char_ID >= 0) {
        _charStats = GuildRosterController.GetCharEntryStats_ByCharAndTypeAndGroup(this.Char_ID, WarcraftStatTypes.Reputation, repGroup);
        } else {
        _charStats = new List<GuildEntryStat>();
        }
      return _charStats;
      }
*/
    public void AssignSpec(int spec1, int spec2, int spec3) {
      switch (this.Char_Class.ToLower()) {
        case "deathknight":
          this.Char_Spec1 = "Blood";
          this.Char_Spec2 = "Frost";
          this.Char_Spec3 = "Unholy";
          break;
        case "druid":
          this.Char_Spec1 = "Balance";
          this.Char_Spec2 = "Feral Combat";
          this.Char_Spec3 = "Restoration";
          break;
        case "hunter":
          this.Char_Spec1 = "Beast Mastery";
          this.Char_Spec2 = "Marksmanship";
          this.Char_Spec3 = "Survival";
          break;
        case "mage":
          this.Char_Spec1 = "Arcane";
          this.Char_Spec2 = "Fire";
          this.Char_Spec3 = "Frost";
          break;
        case "paladin":
          this.Char_Spec1 = "Holy";
          this.Char_Spec2 = "Protection";
          this.Char_Spec3 = "Retribution";
          break;
        case "priest":
          this.Char_Spec1 = "Discipline";
          this.Char_Spec2 = "Holy";
          this.Char_Spec3 = "Shadow Magic";
          break;
        case "rogue":
          this.Char_Spec1 = "Assassination";
          this.Char_Spec2 = "Combat";
          this.Char_Spec3 = "Subtlety";
          break;
        case "shaman":
          this.Char_Spec1 = "Elemental Combat";
          this.Char_Spec2 = "Enhancement";
          this.Char_Spec3 = "Restoration";
          break;
        case "warrior":
          this.Char_Spec1 = "Arms";
          this.Char_Spec2 = "Fury";
          this.Char_Spec3 = "Protection";
          break;
        case "warlock":
          this.Char_Spec1 = "Affliction";
          this.Char_Spec2 = "Demonology";
          this.Char_Spec3 = "Destruction";
          break;
        }

      this.Char_Spec1_Level = spec1;
      this.Char_Spec2_Level = spec2;
      this.Char_Spec3_Level = spec3;

      if (spec1 <= 0 && spec2 <= 0 && spec3 <= 0) {
        this.Char_Spec = "Unspecced";
        this.Char_Spec_Num = -1;
        } else if (spec1 == spec2 && spec1 == spec3) {
        this.Char_Spec = "Full Hybrid";
        this.Char_Spec_Num = 0;
        } else if (spec1 >= spec2 && spec1 >= spec3) {
        this.Char_Spec_Num = 1;
        this.Char_Spec = this.Char_Spec1;
        if (spec1 <= (spec2 * 2) || spec1 <= (spec3 * 2)) {
          this.Char_Spec += " Hybrid";
          }
        } else if (spec2 >= spec1 && spec2 >= spec3) {
        this.Char_Spec_Num = 2;
        this.Char_Spec = this.Char_Spec2;
        if (spec2 <= (spec1 * 2) || spec2 <= (spec3 * 2)) {
          this.Char_Spec += " Hybrid";
          }
        } else if (spec3 >= spec1 && spec3 >= spec2) {
        this.Char_Spec_Num = 3;
        this.Char_Spec = this.Char_Spec3;
        if (spec3 <= (spec1 * 2) || spec3 <= (spec2 * 2)) {
          this.Char_Spec += " Hybrid";
          }
        } else {
        this.Char_Spec_Num = -1;
        this.Char_Spec = "Unknown";
        }

      }
    #endregion
    }
  /*
  /// <summary>
  /// Character entry that represents one game character, used for passing information from the web service calls.
  /// The object is a light-weight version of GuildEntry
  /// </summary>
  public class GuildEntry_WS {
    #region Public Properties
    public int Char_ID {
      get;
      set;
      }
    public int Roster_ID {
      get;
      set;
      }

    public String Char_Server {
      get;
      set;
      }
    public String Char_Guild {
      get;
      set;
      }

    public String Char_Name {
      get;
      set;
      }
    public String Char_Race {
      get;
      set;
      }
    public String Char_Gender {
      get;
      set;
      }
    public String Char_Class {
      get;
      set;
      }
    public int Char_Level {
      get;
      set;
      }
    public String Char_Spec {
      get;
      set;
      }
    public int Char_Spec1_Level {
      get;
      set;
      }
    public int Char_Spec2_Level {
      get;
      set;
      }
    public int Char_Spec3_Level {
      get;
      set;
      }

    public String Char_Prof1 {
      get;
      set;
      }
    public int Char_Prof1_Level {
      get;
      set;
      }
    public String Char_Prof2 {
      get;
      set;
      }
    public int Char_Prof2_Level {
      get;
      set;
      }

    public String Game_Guild_RankName {
      get;
      set;
      }

    public int Primary_Char_Flag {
      get;
      set;
      }
    public String Alt_to_Main_Name {
      get;
      set;
      }
    public int AltCount {
      get;
      set;
      }

    public String PopupHtml {
      get;
      set;
      }

    public String StatName {
      get;
      set;
      }
    public String StatValue {
      get;
      set;
      }
    #endregion
    #region Constructors
    public GuildEntry_WS() {
      }
    public GuildEntry_WS(GuildEntry rosterSrc) {
      this.Char_ID = rosterSrc.Char_ID;
      this.Roster_ID = rosterSrc.Roster_ID;
      this.Char_Server = rosterSrc.Char_Server;
      this.Char_Guild = rosterSrc.Char_Guild;

      this.Char_Name = rosterSrc.Char_Name;
      this.Char_Race = rosterSrc.Char_Race;
      this.Char_Gender = rosterSrc.Char_Gender;
      this.Char_Class = rosterSrc.Char_Class;
      this.Char_Level = rosterSrc.Char_Level;

      this.Char_Spec = rosterSrc.Char_Spec;
      this.Char_Spec1_Level = rosterSrc.Char_Spec1_Level;
      this.Char_Spec2_Level = rosterSrc.Char_Spec2_Level;
      this.Char_Spec3_Level = rosterSrc.Char_Spec3_Level;
      this.Char_Prof1 = rosterSrc.Char_Prof1;
      this.Char_Prof1_Level = rosterSrc.Char_Prof1_Level;
      this.Char_Prof2 = rosterSrc.Char_Prof2;
      this.Char_Prof2_Level = rosterSrc.Char_Prof2_Level;

      this.Game_Guild_RankName = rosterSrc.Game_Guild_RankName;

      this.Primary_Char_Flag = rosterSrc.Primary_Char_Flag;

      this.PopupHtml = rosterSrc.PopupHtml;

      if (rosterSrc.AltCharacters != null) {
        this.AltCount = rosterSrc.AltCharacters.Count;
        } else this.AltCount = 0;

      if (rosterSrc.MainCharacter != null) {
        this.Alt_to_Main_Name = rosterSrc.MainCharacter.Char_Name;
        }

      }
    public GuildEntry_WS(QuickStatListItem rosterSrc) {
      this.Char_ID = rosterSrc.Char_ID;
      this.Roster_ID = rosterSrc.Roster_ID;
      this.Char_Server = rosterSrc.Char_Server;
      this.Char_Guild = rosterSrc.Char_Guild;

      this.Char_Name = rosterSrc.Char_Name;
      this.Char_Race = rosterSrc.Char_Race;
      this.Char_Gender = rosterSrc.Char_Gender;
      this.Char_Class = rosterSrc.Char_Class;
      this.Char_Level = rosterSrc.Char_Level;

      this.Char_Spec = rosterSrc.Char_Spec;
      this.Char_Spec1_Level = rosterSrc.Char_Spec1_Level;
      this.Char_Spec2_Level = rosterSrc.Char_Spec2_Level;
      this.Char_Spec3_Level = rosterSrc.Char_Spec3_Level;
      this.Char_Prof1 = rosterSrc.Char_Prof1;
      this.Char_Prof1_Level = rosterSrc.Char_Prof1_Level;
      this.Char_Prof2 = rosterSrc.Char_Prof2;
      this.Char_Prof2_Level = rosterSrc.Char_Prof2_Level;

      this.Game_Guild_RankName = rosterSrc.Game_Guild_RankName;

      this.Primary_Char_Flag = rosterSrc.Primary_Char_Flag;

      this.PopupHtml = rosterSrc.PopupHtml;

      if (rosterSrc.AltCharacters != null) {
        this.AltCount = rosterSrc.AltCharacters.Count;
        } else this.AltCount = 0;

      if (rosterSrc.MainCharacter != null) {
        this.Alt_to_Main_Name = rosterSrc.MainCharacter.Char_Name;
        }

      this.StatName = rosterSrc.Stat_Entry;
      this.StatValue = rosterSrc.Stat_Value;

      }

    #endregion

    }
  */
  }
